Refine gateway runtime and simplify tokenizer search#1
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors ManagedCode.MCPGateway runtime/catalog internals into smaller components, adds optional gateway initialization (service-provider extension + hosted warmup), and simplifies tokenizer search to a single built-in ChatGPT O200kBase path while updating docs/tests accordingly.
Changes:
- Introduces
McpGatewayRuntimeorchestration split across indexing/search/invocation/embeddings helpers, plus a separateMcpGatewayRegistry. - Adds optional eager initialization via
InitializeManagedCodeMcpGatewayAsync()andAddManagedCodeMcpGatewayIndexWarmup(). - Updates search behavior/tests/docs for tokenizer-based ranking (and optional English query normalization via a keyed
IChatClient).
Reviewed changes
Copilot reviewed 64 out of 77 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ManagedCode.MCPGateway.Tests/TestSupport/TestToolEmbeddingStore.cs | Switches test embedding store to shared internal index helper. |
| tests/ManagedCode.MCPGateway.Tests/TestSupport/TestFunctionFactory.cs | Adds shared AIFunction factory helper for tests. |
| tests/ManagedCode.MCPGateway.Tests/TestSupport/TestChatClient.cs | Adds a test IChatClient for query-normalization scenarios. |
| tests/ManagedCode.MCPGateway.Tests/TestSupport/GatewayTestServiceProviderFactory.cs | Adds optional keyed search-query chat client wiring for tests. |
| tests/ManagedCode.MCPGateway.Tests/Search/SearchTestEnums.cs | Adds tokenizer-search test support + shared enums. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayTokenizerSearchTests.cs | Adds tokenizer strategy coverage and expectations. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayTokenizerSearchEvaluationTests.cs | Adds evaluation threshold test for tokenizer search. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayTokenizerSearchEvaluationSupport.cs | Adds evaluation metric helpers for tokenizer search. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayTokenizerSearchEvaluationQueries.cs | Adds evaluation query buckets. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayTokenizerSearchEvaluationCatalog.cs | Adds 50-tool evaluation catalog for tokenizer search. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewaySearchVectorTests.cs | Splits out vector search tests from prior combined file. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewaySearchTests.cs | Converts to partial and keeps shared tool config helpers. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewaySearchLexicalTests.cs | Adds tokenizer/lexical fallback tests (incl. query normalization). |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewaySearchEmbeddingStoreTests.cs | Adds embedding-store reuse/regeneration tests. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewaySearchBuildTests.cs | Adds registry/index build behavior + concurrency tests. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayInitializationTests.cs | Adds tests for service-provider init + hosted warmup. |
| tests/ManagedCode.MCPGateway.Tests/Search/McpGatewayInMemoryToolEmbeddingStoreTests.cs | Refactors in-memory embedding store tests via helpers. |
| tests/ManagedCode.MCPGateway.Tests/MetaTools/McpGatewayMetaToolTests.cs | Updates tests to use shared TestFunctionFactory. |
| tests/ManagedCode.MCPGateway.Tests/Invocation/McpGatewayInvocationTests.cs | Converts to partial and splits invocation tests. |
| tests/ManagedCode.MCPGateway.Tests/Invocation/McpGatewayInvocationMcpTests.cs | Adds MCP invocation tests in a dedicated file. |
| tests/ManagedCode.MCPGateway.Tests/Invocation/McpGatewayInvocationLocalTests.cs | Adds local invocation tests in a dedicated file. |
| src/ManagedCode.MCPGateway/Registration/McpGatewayServiceProviderExtensions.cs | Adds InitializeManagedCodeMcpGatewayAsync() extension. |
| src/ManagedCode.MCPGateway/Registration/McpGatewayServiceCollectionExtensions.cs | Updates DI wiring and adds hosted warmup registration. |
| src/ManagedCode.MCPGateway/Properties/AssemblyInfo.cs | Exposes internals to the test assembly. |
| src/ManagedCode.MCPGateway/Models/Search/McpGatewaySearchStrategy.cs | Adds explicit search strategy enum. |
| src/ManagedCode.MCPGateway/Models/Search/McpGatewaySearchResult.cs | Adds public search result record. |
| src/ManagedCode.MCPGateway/Models/Search/McpGatewaySearchRequest.cs | Adds public search request record. |
| src/ManagedCode.MCPGateway/Models/Search/McpGatewaySearchQueryNormalization.cs | Adds query-normalization configuration enum. |
| src/ManagedCode.MCPGateway/Models/Search/McpGatewaySearchMatch.cs | Adds public search match record. |
| src/ManagedCode.MCPGateway/Models/Invocation/McpGatewayInvokeResult.cs | Adds public invoke result record. |
| src/ManagedCode.MCPGateway/Models/Invocation/McpGatewayInvokeRequest.cs | Adds public invoke request record. |
| src/ManagedCode.MCPGateway/Models/Embeddings/McpGatewayToolEmbeddingLookup.cs | Adds embedding lookup record. |
| src/ManagedCode.MCPGateway/Models/Embeddings/McpGatewayToolEmbedding.cs | Adds embedding record. |
| src/ManagedCode.MCPGateway/Models/Catalog/McpGatewayToolDescriptor.cs | Adds tool descriptor record. |
| src/ManagedCode.MCPGateway/Models/Catalog/McpGatewaySourceKind.cs | Adds source-kind enum. |
| src/ManagedCode.MCPGateway/Models/Catalog/McpGatewayIndexBuildResult.cs | Adds index build result record. |
| src/ManagedCode.MCPGateway/Models/Catalog/McpGatewayDiagnostic.cs | Adds diagnostic record. |
| src/ManagedCode.MCPGateway/McpGatewayToolSet.cs | Extracts tool descriptions into constants. |
| src/ManagedCode.MCPGateway/ManagedCode.MCPGateway.csproj | Adds hosting/tokenizer dependencies. |
| src/ManagedCode.MCPGateway/Internal/Warmup/McpGatewayIndexWarmupService.cs | Adds hosted background index warmup service. |
| src/ManagedCode.MCPGateway/Internal/Serialization/McpGatewayJsonSerializer.cs | Adds centralized JSON normalization helpers. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Search/McpGatewaySearchTokenizerFactory.cs | Adds single built-in tokenizer factory. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Search/McpGatewayRuntime.Tokenization.cs | Implements token/lexical term extraction and profiles. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Search/McpGatewayRuntime.TokenSearchSegments.cs | Builds token-search segments from descriptors/queries/context. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Search/McpGatewayRuntime.Search.cs | Implements search flow (vector + tokenizer/lexical ranking). |
| src/ManagedCode.MCPGateway/Internal/Runtime/Search/McpGatewayRuntime.QueryNormalization.cs | Adds optional English query normalization via keyed IChatClient. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Search/McpGatewayRuntime.Context.cs | Adds context flattening for ranking input. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Invocation/McpGatewayRuntime.InvocationResults.cs | Adds MCP output extraction + JSON scalar normalization. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Invocation/McpGatewayRuntime.Invocation.cs | Implements invocation resolution/mapping and MCP/meta attachment. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Embeddings/McpGatewayRuntime.Embeddings.cs | Adds embedding generator/store resolution + fingerprinting. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Core/McpGatewayRuntime.cs | Introduces core runtime constants/state and DI-resolved options. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Core/McpGatewayRuntime.Types.cs | Adds internal runtime records/leasing helpers. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Core/McpGatewayRuntime.Snapshot.cs | Adds snapshot refresh logic based on registry versioning. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Catalog/McpGatewayRuntime.Indexing.cs | Implements single-flight index builds + embeddings persistence. |
| src/ManagedCode.MCPGateway/Internal/Runtime/Catalog/McpGatewayRuntime.Descriptors.cs | Builds descriptors/documents from tools and schemas. |
| src/ManagedCode.MCPGateway/Internal/Embeddings/McpGatewayToolEmbeddingStoreIndex.cs | Extracts embedding store index helper (clone, lookup, remove). |
| src/ManagedCode.MCPGateway/Internal/Catalog/Sources/McpGatewayToolSourceRegistrations.cs | Refactors source registrations and MCP client caching/concurrency. |
| src/ManagedCode.MCPGateway/Internal/Catalog/Sources/McpGatewayRegistrationCollection.cs | Adds thread-safe registration collection. |
| src/ManagedCode.MCPGateway/Internal/Catalog/Sources/McpGatewayClientFactory.cs | Uses assembly version for MCP client info (no hardcoding). |
| src/ManagedCode.MCPGateway/Internal/Catalog/McpGatewayRegistry.cs | Adds separate registry service implementing catalog source + disposal gate. |
| src/ManagedCode.MCPGateway/Internal/Catalog/McpGatewayOperationGate.cs | Adds lifecycle gate for registry operations vs dispose. |
| src/ManagedCode.MCPGateway/Internal/Catalog/McpGatewayDefaults.cs | Introduces default source id constant. |
| src/ManagedCode.MCPGateway/Internal/Catalog/McpGatewayCatalogSourceSnapshot.cs | Adds snapshot record (version + registrations). |
| src/ManagedCode.MCPGateway/Internal/Catalog/IMcpGatewayCatalogSource.cs | Adds internal catalog source abstraction. |
| src/ManagedCode.MCPGateway/Embeddings/McpGatewayInMemoryToolEmbeddingStore.cs | Adds public in-memory embedding store using internal index helper. |
| src/ManagedCode.MCPGateway/Configuration/McpGatewayServiceKeys.cs | Adds keyed service key for search-query chat client. |
| src/ManagedCode.MCPGateway/Configuration/McpGatewayOptions.cs | Adds new options surface for strategy/normalization/defaults and registration helpers. |
| src/ManagedCode.MCPGateway/Abstractions/Embeddings/IMcpGatewayToolEmbeddingStore.cs | Introduces public embedding store abstraction. |
| src/ManagedCode.MCPGateway/Abstractions/Catalog/IMcpGatewayRegistry.cs | Introduces public registry abstraction for post-build mutations. |
| docs/Features/SearchQueryNormalizationAndRanking.md | Documents normalization + tokenizer ranking design and verification. |
| docs/Architecture/Overview.md | Documents new module boundaries and dependency rules. |
| README.md | Updates usage docs for strategies, warmup, normalization, and defaults. |
| Directory.Packages.props | Adds hosting/tokenizer package versions. |
| Directory.Build.props | Bumps package version to 0.2.0. |
| AGENTS.md | Updates repo workflow rules and documentation/testing guidance. |
Comments suppressed due to low confidence (1)
src/ManagedCode.MCPGateway/Internal/Catalog/Sources/McpGatewayToolSourceRegistrations.cs:196
- In
GetClientAsync,createdTaskis constructed before theCompareExchangesucceeds. Under concurrent callers this can start multipleCreateClientAsync(...).AsTask()executions; tasks that lose the CAS still run and can create extraMcpClientinstances (and potentially leak/dispose incorrectly). Consider using a single-flight pattern that only startsCreateClientAsyncafter winning the CAS (e.g., store aTaskCompletionSource<McpClient>/lazy initializer, or create the task inside the successfulCompareExchangebranch).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/ManagedCode.MCPGateway/Internal/Runtime/Catalog/McpGatewayRuntime.Indexing.cs
Show resolved
Hide resolved
src/ManagedCode.MCPGateway/Internal/Serialization/McpGatewayJsonSerializer.cs
Outdated
Show resolved
Hide resolved
src/ManagedCode.MCPGateway/Internal/Serialization/McpGatewayJsonSerializer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8abca740bd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/ManagedCode.MCPGateway/Internal/Runtime/Catalog/McpGatewayRuntime.Indexing.cs
Outdated
Show resolved
Hide resolved
|
Addressed all current review comments in . Changes included:
Verification:
Build succeeded. Time Elapsed 00:00:00.44
Test run summary: Passed!
Build succeeded. Time Elapsed 00:00:00.40
Language files blank comment codeC# 76 1023 6 5973SUM: 76 1023 6 5973Result: 65/65 tests passed, 0 warnings, 0 diagnostics. |
|
Addressed all current review comments in Changes included:
Verification:
Result: 65/65 tests passed, 0 warnings, 0 diagnostics. |
Summary
Verification